<template>
  <div>
    <div class="clearfix" id="login_wrap">
      <div id="login" >
        <h2 class="title">登录页</h2>
        <div class="login--account">
          <span>账号：</span>
          <input type="text" placeholder="随便输" name="account" v-model.trim="username" />
        </div>
        <div class="login--password">
          <span>密码：</span>
          <input type="password" placeholder="随便输" name="password" v-model.trim="password" />
        </div>
        <p class="login--btn">
          <el-button id="loginBtn" type="primary" @click="golayout">登录</el-button>
        </p>
        <p class="info">账号: admin是超级管理员</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router';
import { ref, getCurrentInstance, reactive, onMounted } from 'vue';
import { useuserInfoStore } from '@/store/modules/login'
const userInfoStore = useuserInfoStore()
//全局导入
const cxt = getCurrentInstance()
const API = cxt.appContext.config.globalProperties.$API
const router = useRouter()

const username = ref('')
const password=ref('')
const golayout = async () => {
  const result = await API.login({ user: username.value, pwd: password.value })
  
  if (result.status == 200) {
    userInfoStore.changeuserInfo({ username: username.value, accessToken:result.accessToken,userId:result.id,role:result.role})
    router.push('/layout')
  }
  
}
</script>

<style lang="less" scoped>
.title {
  text-align: center;
  font-size: 22px;
}

#login_wrap {
  position: relative;
  background: rgba(64, 64, 194, 0.1);
  height: 100%;
  margin-top: 300px;

  >div {
    background: #fff;
    width: 420px;
    height: 300px;
    padding: 30px 40px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    >div {
      padding: 10px 0;
      border-bottom: 1px solid #ddd;
      background: #fff;

      &.login--account {
        margin: 25px 0 30px;
        background: #fff;
      }

      span {
        color: #666;
        display: inline-block;
        width: 84px;
        font-size: 20px;
        background: #fff;
      }

      input {
        background: none;
        font-size: 16px;
        border: none;
        height: 30px;
        width: 280px;
        padding-left: 12px;
        box-sizing: border-box;
        color: #666;
        background: #fff;
        outline: none;

        &.error {
          border: 1px solid #f00;
        }

        &::-webkit-input-placeholder {
          color: #aaa;
        }
      }
    }

    p {
      text-align: right;

      &.login--btn {
        button {
          width: 100%;
          height: 50px;
          font-size: 18px;
          // border: none;
          margin-top: 30px;
          // color: #fff;
          // border-radius: 6px;
          // cursor: pointer;
        }
      }

      a {
        color: #fff;
        display: inline-block;
        padding: 0 15px;
        font-size: 14px;
      }
    }
  }
}

.info {
  color: #999;
  margin-top: 8px;
  text-align: center !important;
}
</style>